<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
date_default_timezone_set('Asia/Chongqing');

$ENVIRONMENT_FLAG = 0; // 0 开发环境 1 生产环境
if ($ENVIRONMENT_FLAG == 0){
	// ########## 开发环境 ##########
	$DBCONF = array(
	    'HOST' => 'localhost',
	    'USER' => 'root',
	    'PASSWORD' => '123456',
	    'DB' => 'touzhu'
	);
	
}else {
	// ########## 生产环境 ##########
	$DBCONF = array(
	    'HOST' => 'localhost',
	    'USER' => 'touzhu',
	    'PASSWORD' => 'touzhu211@mysql',
	    'DB' => 'touzhu'
	);
	
}

$GLOBAL_FROM = array(
    1 => '365Bet',
    2 => '金宝博'
);

$GLOBAL_WANFA_NUM = array(
    1 => '上半场亚洲盘角球',
    2 => '亚洲盘角球',
	3 => '上半场大小盘',
	4 => '大小盘'
);

$GLOBAL_PEISHUIFANGSHI = array(
	1 => '365大配188小',
	2 => '365小配188大'
);

$GLOBAL_MATCH_STATUS = array(
	1 => '上半场',
	2 => '中场',
	3 => '下场',
	4 => '结束'
);

$GLOBAL_RECORD_TYPE = array(
	1 => '上半场开始',
	2 => '上半场结束',
	3 => '中场开始',
	4 => '中场结束',
	5 => '下半场开始',
	6 => '下半场结束',
	7 => '中场中间'
);

// 打水设置
function conf_pair_sets($opt = 'get', $wanfa = 'jiaoqiupan', $vals = array()){
	$re = false;
	$set_file = dirname(__FILE__) . '/pairsetfile_' . $wanfa . '.txt';
	$mem_key = 'pairsetvals_' . $wanfa;
	
	$mem_obj = new Memcache;
	$mem_obj->connect("127.0.0.1",  11211);
	
	if ($opt == 'set'){
		$mem_obj->set($mem_key, $vals);
		$set_str = date('Y-m-d H:i:s') . "\t" . serialize($vals) . "\n";
		$re = @file_put_contents($set_file, $set_str, FILE_APPEND);
	}elseif ($opt == 'get'){
		$re = $mem_obj->get($mem_key);
		// 读缓存失败，从文件中获取
		if (!is_array($re) && file_exists($set_file)){
			$_file_con = @file($set_file);
			if (is_array($_file_con)){
				$_set_num = count($_file_con) - 1;
				if (isset($_file_con[$_set_num])){
					list($_tmp, $set_str) = explode("\t", trim($_file_con[$_set_num]));
					$re = unserialize($set_str);
				}
			}
		}
	}
	
	$mem_obj->close();
	return $re;
}

// 抓取数据开关
function conf_switch_sets($opt = 'get', $val = ''){
	$re = false;
	$set_file = dirname(__FILE__) . '/fcsetfile.txt';
	$mem_key = 'fcsetval';
	
	$mem_obj = new Memcache;
	$mem_obj->connect("127.0.0.1",  11211);
	
	if ($opt == 'set'){
		$mem_obj->set($mem_key, $val);
		$set_str = date('Y-m-d H:i:s') . "\t{$val}\n";
		$re = @file_put_contents($set_file, $set_str, FILE_APPEND);
	}elseif ($opt == 'get'){
		$re = $mem_obj->get($mem_key);
		// 读缓存失败，从文件中获取
		if ($re == false && file_exists($set_file)){
			$_file_con = @file($set_file);
			if (is_array($_file_con)){
				$_set_num = count($_file_con) - 1;
				if (isset($_file_con[$_set_num])){
					list($_tmp, $re) = explode("\t", trim($_file_con[$_set_num]));
				}
			}
		}
	}
	
	$mem_obj->close();
	return $re;
}
